package com.ds.infrastructure.hyperspace.container.internal.util;

import io.netty.util.ReferenceCounted;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: yaozh
 * @Description:
 */
@Slf4j
public class NettyReleaseUtil {

    private NettyReleaseUtil() { }

    /**
     * 完全释放数据
     *
     * @param data
     */
    public static void completelyReleaseData(Object data) {
        if (data instanceof ReferenceCounted) {
            ReferenceCounted referenceCounted = (ReferenceCounted) data;
            if (referenceCounted.refCnt() > 0) {
                referenceCounted.release(referenceCounted.refCnt());
            }
        }
    }

    public static void releaseData(Object data) {
        if (data instanceof ReferenceCounted) {
            ReferenceCounted referenceCounted = (ReferenceCounted) data;
            if (referenceCounted.refCnt() > 0) {
                referenceCounted.release();
            }
        }
    }
}
